package cn.zktr.Personnel.controllers.tantiantian;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsZJnxx;
import cn.zktr.Personnel.model.pojos.PerTngRus;
import cn.zktr.Personnel.model.service.tantiantian.SlySetService;
import cn.zktr.Personnel.model.service.tantiantian.TngRusService;

@Controller
public class TrainingCourseController {
		
	/**
	 * 培训课程
	 */
	@Autowired
	private TngRusService russer;
	/**
	 * 薪资套帐
	 */
	@Autowired
	private SlySetService slyser;

	// 培训课程
	@RequestMapping("ttt/training-course")
	public void TrainingCourse(HttpSession session) {
		//查询所有讲师
		JSONArray emp = russer.seleRusEmp();
		session.setAttribute("rus_emp", emp);
		//查询所有技能
		JSONArray jnxx = russer.seleJnxx();
		session.setAttribute("rus_jnxx", jnxx);
	}

	// TrainingCourse
	@RequestMapping("TrainingCourse")
	@ResponseBody
	public Map<String, Object> TrainingCourse(int page, int rows,HttpSession session) {
		//查询所有讲师
		JSONArray emp = russer.seleRusEmp();
		session.setAttribute("rus_emp", emp);
		//查询所有技能
		JSONArray jnxx = russer.seleJnxx();
		session.setAttribute("rus_jnxx", jnxx);
		
		Map<String, Object> map = new HashMap<>();
		map.put("total", russer.seleRusAll().size());
		Page<Object> p = PageHelper.startPage(page, rows);
		JSONArray findAll = russer.seleRusAll();
		// 页内容
		map.put("rows", findAll);
		return map;
	}
	@RequestMapping("add_rus")
	@ResponseBody
	public void add_rus(PerTngRus rus,Integer empid,Integer jnxxid) {
			rus.setRusdate(new Timestamp(System.currentTimeMillis()));
			//培训老师
			PerPmsEmp emp = slyser.seleEmpids(empid);
			//培训技能
			PerPmsZJnxx jnxx = russer.seleJnxxById(jnxxid);
			rus.setPerPmsEmp(emp);
			rus.setPerPmsZJnxx(jnxx);
			PerTngRus addRus = russer.addRus(rus);

	}
	//根据课程名称查询TrainingCourse_name
	@RequestMapping("TrainingCourse_name")
	@ResponseBody
	public JSONArray TrainingCourse_name(String text) {
		return russer.TrainingCourse_name(text);

	}
}
